<?php
/**
 * Created by PhpStorm.
 * User: yuanjie
 * Date: 2017/4/6
 * Time: 上午10:59
 */
class Scws extends Eloquent
{
    /*
     * 初始化分词索引
     * 入参
     *  $search - 输入
     * 返回
     *  0-成功
     *  result - array 分词结果
     * */
    public static function participle($search){
        try{
            $_result = array();
            $so = scws_new();
            $so->set_charset('utf8');
            $so->set_dict('/usr/local/scws/etc/dict.utf8.xdb');
            $so->set_rule('/usr/local/scws/etc/rules.utf8.ini');
            $so->send_text($search);
            while ($tmp = $so->get_result()){
                foreach ($tmp as $_tmp){
                    if(stristr($_tmp['attr'],'n') && ($_tmp['attr'] != 'un')){
                        if(!in_array($_tmp['word'],$_result)){
                            array_push($_result,$_tmp['word']);
                        }
                    }
                }
            }
            $result = array(
                'code' => 0,
                'result' => $_result
            );
            $so->close();
        }catch (Exception $e){
            $result = array(
                'code' => -1,
                'result' => $e
            );
        }
        return $result;
    }
}